<template>
	<view class="box">
		<view class="register_box">
			<!-- <view class="register_top flex1">
				<view class="chencked">
					个人注册
				</view>
				<view @click="toEnterPrise()">
					企业注册
				</view>
			</view> -->
			<view class="forget_content">
				<view class="item flex0">
					<view class="forget_lable">
						手机号码:
					</view>
					<view class="forget_input">
						<input type="number" class="login_input" maxlength="11" v-model="phone" placeholder="请输入手机号码" />
					</view>
				</view>
				<view class="item flex0">
					<view class="forget_lable">
						验证码:
					</view>
					<view class="forget_input1 flex0">
						<input type="number" class="login_input codeinput" maxlength="6" v-model="code" placeholder="请输入验证码"/>
						<view class="obtain-code" :class="{'getactive':iscode}" @click="phone_code">
							{{getCode}}
						</view>
					</view>
				</view>
				<!-- <view class="item flex0">
					<view class="forget_lable">
						邀请码:
					</view>
					<view class="forget_input">
						<input type="number" maxlength="11" v-model="invitation" placeholder="请输入邀请码" />
					</view>
				</view> -->
				<view class=" chenkeduser_box_pent">
					<view class="chenkeduser_box"  @click="ifchen">
							<image v-if="!ifchenked" src="../../static/images/login/weixuanzhong-icon.png" mode=""></image>
							<image v-if="ifchenked" src="../../static/images/login/xuanzhong-icon.png" mode=""></image>
					</view>
					<view class="chenkeduser_box_text" >
						请勾选并同意 <text style="color: #FF4300;"  @click="Agreement(0)">《隐私协议》</text>和<text style="color: #FF4300;"  @click="Agreement(1)">《服务协议》</text>
					</view>
				</view>
				<view class="fromsubmit-btn" @click="fromsubmit()">
					立即注册
				</view>
			</view>
		</view>
		
		
		<view class="shadow" v-if="Agreemen" @click="Close()">
			<view class="frameBox">
				 <scroll-view class="scroll-view" scroll-y="true">
				    <view v-html="frame"></view>	 
				  </scroll-view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 控制类
				Agreemen:false,
				chencked: true,
				cloershow: false,
				username: "",
				userpass: "",
				phone:'',
				code:'',
				type: "text",
				isshowChenk: false,
				getCode: "获取验证码",
				iscode: true,
				time: 60,
				ifchenked: false,
				client:"",
				frame:"",
				invitation:"",//邀请码
				AgreementIndex:0
			}
		},
	created() {
		this.getAgreement()
	},
	onLoad() {
		if(uni.getStorageSync("InvitationCode")){
			this.invitation=uni.getStorageSync("InvitationCode")
		}
	},
		methods:{
			Agreement(index){
				this.AgreementIndex=index
				this.Agreemen=true;
			},
			getAgreement(){
				let url=""
				if(this.AgreementIndex==0){
					url='/mobile/index.php?act=document&op=privacy_doc'
				}else{
					url='/mobile/index.php?act=document&op=user_doc'
				}
				let that=this;
				this.$util.request({//获取用户协议
					url: url,
					method: 'post',
					data: {},
				}).then(function(res) {
					that.frame=res.datas.content
				})
			},
			Close(){
				this.Agreemen=false;
			},
			fromsubmit(){
				let that=this;
				switch(uni.getSystemInfoSync().platform){
				    case 'android':
						that.client="android"
				       break;
				    case 'ios':
						that.client="ios" 
				       break;
				    default:
						that.client="wap"
				    break;
				}
				if(that.phone){
					// uni.navigateBack({
					// 	url:'../home/home'
					// })
					if(that.code){
						if(that.ifchenked){
							this.$util.request({//立即注册
									url:'/mobile/index.php?act=login&op=register',
									method:'post',
									data:{
										vercode:that.code,
										regtype:"Ismobilereg",
										username:that.phone,
										client:that.client,
										share_id:that.invitation
									}
								}).then(res=>{
									if(res.error_code==0){
										uni.setStorageSync("key", res.datas.key);
										uni.setStorageSync("api_member_name", res.datas.username)
										uni.setStorageSync("api_member_id", res.datas.member_id)
										uni.showToast({
											title:"注册成功",
											icon:"none",
											success: () => {
												setTimeout(()=>{
													uni.switchTab({
														url:'../home/index'
													})
												},1000)
											}
										})
									}else{
										uni.showToast({
											title: res.message,
											icon: "none"
										})
									}
									
								})
							}else{
								uni.showToast({
									title: "请同意服务协议",
									icon: "none"
								})
							}
						}else{
							uni.showToast({
								title: "验证码不能为空",
								icon: "none"
							})
						}
				}else{
					uni.showToast({
						title: "请输入手机号",
						icon: "none"
					})
				}
	
			},
			
			code_request(){
				 if(!(/^1[3456789]\d{9}$/.test(thgiuphone))){
					uni.showToast({
						title:'手机号码有误，请重填'
					})
				}
			},
			// toEnterPrise(){
			// 	uni.redirectTo({
			// 		url:"./enterprise"
			// 	})
			// },
			// 切换tab
			chenckedFunc(type) {
				let that = this;
				console.log(type);
				if (type == true) {
					return false
				} else {
					that.chencked = !that.chencked
				}
			},
			ifchen() {
				let that = this;
				that.ifchenked = !that.ifchenked;
			},
			phone_code() {
				let that=this;
				if(that.phone){
					if(that.iscode){
						that.iscode = false;
						this.$util.request({//获取验证码
							url: '/mobile/index.php?act=login&op=sendCode',
							method: 'post',
							data: {
								"mobile":that.phone
							},
						}).then(function(res) {
							if(res.error_code==0){
								let codesetInterval = setInterval(() => {
									that.time--;
									that.getCode = that.time + "s"
									if (that.time <= 0) {
										console.log(that.time)
										clearInterval(codesetInterval);
										that.getCode = "获取验证码";
										that.iscode = true;
										that.time=60;
										console.log(that.time)
									}
								}, 1000)
							}else{
								uni.showToast({
									title:res.message,
									icon: "none"
								})
								that.iscode = true;
							}
							console.log(res)
						})
					}
				}else{
					uni.showToast({
						title: "请输入手机号码",
						icon: "none"
					})
				}
			}

		}
	}
</script>


<style scoped lang="scss">
	page{
		background-color: #FFFFFF;
	}
	.box{
		height: 100%;
		background-color: #FFFFFF;
	}
	/deep/ .chenkeduser_box{
		margin-left: 0rpx !important;
	}
	.login_input {
		text-align: left;
		width: 300rpx;
		box-sizing: border-box;
		padding-left: 0;
		font-size: 28rpx !important;
		border: none;
		padding-right: 0;
		margin-left: 10rpx;
		outline: none;
	}
	.register_box{
		position: fixed;
	}
	.scroll-view{
		height: 800rpx;
		
	}
	.shadow{
		position: fixed;
		top: 0;
		width: 100%;
		height: 100vh;
		background-color: rgba(51,51,51,0.2);
		z-index: 888888;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.frameBox{
		width: 90%;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.chenkeduser_box_pent {
		display: flex;
		align-items: center;
		margin-top: 30rpx;
		margin-left: 14rpx;
		position: relative;

	}

	uni-page-body {
		background-color: #FFFFFF;

		color: rgb(102, 102, 102);
	}

	.forget_content {
		width: 750rpx;
		padding: 0 50rpx;
		font-size: 24upx;
		box-sizing: border-box;
		margin-top: 200rpx;
	}
	
	.forget_content .item {
		width: 650rpx;
		height: 90rpx;
		border-radius: 50rpx;
		border: 1rpx solid #EEEEEE;
		margin-bottom: 50rpx;
	}
	.forget_content .item .forget_lable {
		font-size: 28rpx;
		font-weight: 400;
		color: #323232;
		width: 120rpx;
		margin-left: 57rpx;
	}
	
	.forget_content .item .forget_input {
		width: 400rpx;
		font-size: 28rpx;
	
	}
	.forget_input1{
		width: 450rpx;
	}
	
	.obtain-code{
		background: #FFFFFF;
		color: #FF4300;
	}
	.register_top {
		padding: 70upx 130upx;
		font-weight: 700;
		font-size: 28px;
		font-family: "Microsoft YaHei";
		color: rgb(51, 51, 51);



	}

	.register_top view {
		position: relative;
	}

	.register_top view {
		position: relative;
		text-align: center;
	}

	.register_top .chencked::before {
		position: absolute;
		content: "";

		background-image: -moz-linear-gradient(172deg, rgb(191, 2, 80) 0%, rgb(249, 29, 112) 100%);
		background-image: -webkit-linear-gradient(172deg, rgb(191, 2, 80) 0%, rgb(249, 29, 112) 100%);
		background-image: -ms-linear-gradient(172deg, rgb(191, 2, 80) 0%, rgb(249, 29, 112) 100%);
		width: 60upx;
		margin: 0px auto;
		text-align: center;
		height: 6upx;
		bottom: 0px;
		left: 28upx;
		border-radius: 5upx;
		transform: 1s;



	}

	.codeinput {
		width: 300upx;
	}

	.forgeticon {
		width: 22upx;
		height: 28upx;
		margin-right: 10upx;
	}

	.chenkeduser_box {
		padding-top: 10rpx;
		box-sizing: border-box;
		margin-left: 50rpx;
	}

	.chenkeduser_box image {
		height: 30rpx;
		width: 30rpx;
	}
	.chenkeduser_box_text{
		line-height: 0;
		margin-left: 10rpx;
	}
	.fromsubmit-btn{
		margin-top: 90rpx;
		width: 650rpx;
		height: 90rpx;
		background: #FF4300;
		border-radius: 50rpx;
		text-align: center;
		line-height: 90rpx;
		font-size: 36rpx;
		font-weight: 400;
		color: #FFFFFF;
	}
</style>
